/**
 * Copy from PixiJS v6
 * WebGL internal formats, including compressed texture formats provided by extensions
 */
export enum INTERNAL_FORMATS {
  // WEBGL_compressed_texture_s3tc
  COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
  COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
  COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
  COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,

  // WEBGL_compressed_texture_s3tc_srgb
  COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 35917,
  COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 35918,
  COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 35919,
  COMPRESSED_SRGB_S3TC_DXT1_EXT = 35916,

  // WEBGL_compressed_texture_etc
  COMPRESSED_R11_EAC = 0x9270,
  COMPRESSED_SIGNED_R11_EAC = 0x9271,
  COMPRESSED_RG11_EAC = 0x9272,
  COMPRESSED_SIGNED_RG11_EAC = 0x9273,
  COMPRESSED_RGB8_ETC2 = 0x9274,
  COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
  COMPRESSED_SRGB8_ETC2 = 0x9275,
  COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
  COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
  COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,

  // WEBGL_compressed_texture_pvrtc
  COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
  COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
  COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
  COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,

  // WEBGL_compressed_texture_etc1
  COMPRESSED_RGB_ETC1_WEBGL = 0x8D64,

  // WEBGL_compressed_texture_atc
  COMPRESSED_RGB_ATC_WEBGL = 0x8C92,
  COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL = 0x8C92, // TODO: Probably a bug on the MDN site
  COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL = 0x87EE,

  // WEBGL_compressed_texture_astc
  COMPRESSED_RGBA_ASTC_10x10_KHR = 37819,
  COMPRESSED_RGBA_ASTC_10x5_KHR = 37816,
  COMPRESSED_RGBA_ASTC_10x6_KHR = 37817,
  COMPRESSED_RGBA_ASTC_10x8_KHR = 37818,
  COMPRESSED_RGBA_ASTC_12x10_KHR = 37820,
  COMPRESSED_RGBA_ASTC_12x12_KHR = 37821,
  COMPRESSED_RGBA_ASTC_4x4_KHR = 37808,
  COMPRESSED_RGBA_ASTC_5x4_KHR = 37809,
  COMPRESSED_RGBA_ASTC_5x5_KHR = 37810,
  COMPRESSED_RGBA_ASTC_6x5_KHR = 37811,
  COMPRESSED_RGBA_ASTC_6x6_KHR = 37812,
  COMPRESSED_RGBA_ASTC_8x5_KHR = 37813,
  COMPRESSED_RGBA_ASTC_8x6_KHR = 37814,
  COMPRESSED_RGBA_ASTC_8x8_KHR = 37815,
  COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 3781,
  COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 37847,
  COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 37849,
  COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 37850,
  COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 37852,
  COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 37853,
  COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 37840,
  COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 37841,
  COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 37842,
  COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 37843,
  COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 37844,
  COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 37845,
  COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 37846,
  COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 37847,
}

/**
 * Maps the compressed texture formats in {@link PIXI.INTERNAL_FORMATS} to the number of bytes taken by
 * each texel.
 *
 * @memberof PIXI
 * @static
 * @ignore
 */
export const INTERNAL_FORMAT_TO_BLOCK_SIZE: { [id: number]: [number, number] } = {
  // WEBGL_compressed_texture_s3tc
  [INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT]: [4, 4],

  // WEBGL_compressed_texture_s3tc
  [INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT]: [4, 4],

  // WEBGL_compressed_texture_etc
  [INTERNAL_FORMATS.COMPRESSED_R11_EAC]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RG11_EAC]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2]: [4, 4],

  // WEBGL_compressed_texture_pvrtc
  [INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG]: [8, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG]: [8, 4],

  // WEBGL_compressed_texture_etc1
  [INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL]: [4, 4],

  // @see https://www.khronos.org/registry/OpenGL/extensions/AMD/AMD_compressed_ATC_texture.txt
  // WEBGL_compressed_texture_atc
  [INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL]: [4, 4],

  // astc
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_4x4_KHR]: [4, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x5_KHR]: [5, 5],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x6_KHR]: [6, 6],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x8_KHR]: [8, 8],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x10_KHR]: [10, 10],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x12_KHR]: [12, 12],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x5_KHR]: [10, 5],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x6_KHR]: [10, 6],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x8_KHR]: [10, 8],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x10_KHR]: [12, 10],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x4_KHR]: [5, 4],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x5_KHR]: [6, 5],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x5_KHR]: [8, 5],
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x6_KHR]: [8, 6]
};

export const INTERNAL_FORMATS_TO_EXTENSION_NAME: { [key: number]: string } = {
  // WEBGL_compressed_texture_s3tc
  [INTERNAL_FORMATS.COMPRESSED_RGB_S3TC_DXT1_EXT]: 'WEBGL_compressed_texture_s3tc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT1_EXT]: 'WEBGL_compressed_texture_s3tc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT3_EXT]: 'WEBGL_compressed_texture_s3tc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT]: 'WEBGL_compressed_texture_s3tc',

  // WEBGL_compressed_texture_s3tc
  [INTERNAL_FORMATS.COMPRESSED_SRGB_S3TC_DXT1_EXT]: 'WEBGL_compressed_texture_s3tc_srgb',
  [INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT]: 'WEBGL_compressed_texture_s3tc_srgb',
  [INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT]: 'WEBGL_compressed_texture_s3tc_srgb',
  [INTERNAL_FORMATS.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT]: 'WEBGL_compressed_texture_s3tc_srgb',

  // WEBGL_compressed_texture_etc
  [INTERNAL_FORMATS.COMPRESSED_R11_EAC]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_SIGNED_R11_EAC]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_RG11_EAC]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_SIGNED_RG11_EAC]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_RGB8_ETC2]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA8_ETC2_EAC]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_SRGB8_ETC2]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2]: 'WEBGL_compressed_texture_etc',
  [INTERNAL_FORMATS.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2]: 'WEBGL_compressed_texture_etc',

  // WEBGL_compressed_texture_pvrtc
  [INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG]: 'WEBGL_compressed_texture_pvrtc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG]: 'WEBGL_compressed_texture_pvrtc',
  [INTERNAL_FORMATS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG]: 'WEBGL_compressed_texture_pvrtc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG]: 'WEBGL_compressed_texture_pvrtc',

  // WEBGL_compressed_texture_etc1
  [INTERNAL_FORMATS.COMPRESSED_RGB_ETC1_WEBGL]: 'WEBGL_compressed_texture_etc1',

  // WEBGL_compressed_texture_atc
  [INTERNAL_FORMATS.COMPRESSED_RGB_ATC_WEBGL]: 'WEBGL_compressed_texture_atc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL]: 'WEBGL_compressed_texture_atc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL]: 'WEBGL_compressed_texture_atc',

  // astc
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_4x4_KHR]: 'WEBGL_compressed_texture_astc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_5x5_KHR]: 'WEBGL_compressed_texture_astc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_6x6_KHR]: 'WEBGL_compressed_texture_astc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_8x8_KHR]: 'WEBGL_compressed_texture_astc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_10x10_KHR]: 'WEBGL_compressed_texture_astc',
  [INTERNAL_FORMATS.COMPRESSED_RGBA_ASTC_12x12_KHR]: 'WEBGL_compressed_texture_astc',
}